<template>
    <!-- 对话框表单 -->
    <!-- 建议使用 Prettier 格式化代码 -->
    <!-- el-form 内可以混用 el-form-item、FormItem、ba-input 等输入组件 -->
    <el-dialog
        class="ba-operate-dialog"
        :close-on-click-modal="false"
        :model-value="['Add', 'Edit'].includes(baTable.form.operate!)"
        @close="baTable.toggleForm"
        width="50%"
    >
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                <span v-if="baTable.form.items.sz == '支出'">{{ t('添加明细') }}</span>
                <span v-if="baTable.form.items.sz == '收入'">{{ t('余额充值') }}</span>
                
                <span v-if="['Edit'].includes(baTable.form.operate!)">({{ t('编辑') }})</span>

            </div>
        </template>
        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div
                class="ba-operate-form"
                :class="'ba-' + baTable.form.operate + '-form'"
                :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
            >
                <el-form
                    v-if="!baTable.form.loading"
                    ref="formRef"
                    @submit.prevent=""
                    @keyup.enter="baTable.onSubmit(formRef)"
                    :model="baTable.form.items"
                    label-position="right"
                    :label-width="baTable.form.labelWidth + 'px'"
                    :rules="rules"
                >
                <!-- baTable.table.extend.admin_id -->

                    
                
                    <FormItem :label="t('账户')" type="string" v-model="baTable.table.extend.admin_name" :input-attr="{ disabled: true }" />
                    <FormItem :label="t('余额')" type="string" v-model="baTable.table.extend.amount" :input-attr="{ disabled: true }" />
                    
                    <el-form-item :label="t('金额')">
                        <el-input v-model="baTable.form.items!.money">
                            <template #prepend>
                                <span v-if="baTable.form.items.sz == '收入'">{{ t('收入') }}</span>
                                <span v-if="baTable.form.items.sz == '支出'">{{ t('支出') }}</span>
                            </template>
                        </el-input>
                    </el-form-item>
                    <el-form-item :label="t('时间')">
                        <el-date-picker v-model="baTable.form.items!.trade_time" type="datetime" />
                    </el-form-item>
                    <el-form-item :label="t('类型')" v-if="baTable.form.items.sz == '支出'">
                        <el-radio-group v-model="baTable.form.items!.type" border>
                            <el-col :span="6"><el-radio label="餐费" name="type">{{ t('餐费') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="修理费" name="type">{{ t('修理费') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="交通费" name="type">{{ t('交通费') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="加油费" name="type">{{ t('加油费') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="应酬费" name="type">{{ t('应酬费') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="通讯费" name="type">{{ t('通讯费') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="采购费" name="type">{{ t('采购费') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="工资" name="type">{{ t('工资') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="办公室_仓库" name="type">{{ t('办公室') }}&{{ t('仓库') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="办公用品" name="type">{{ t('办公用品') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="物流费" name="type">{{ t('物流费') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="暂付款项" name="type">{{ t('暂付款项') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="租车费" name="type">{{ t('租车费') }}</el-radio></el-col>
                            <el-col :span="6"><el-radio label="其他" name="type">{{ t('其他') }}</el-radio></el-col>
                        </el-radio-group>
                    </el-form-item>
                    <FormItem :label="t('发票')" type="file" v-model="baTable.form.items!.invoice" :input-attr="{ hideSelectFile: true }" />
                    <FormItem :label="t('内容')" type="textarea" v-model="baTable.form.items!.note"  :input-attr="{ rows: 4 }" />
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm()">{{ t('取消') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('保存') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import type { FormInstance, FormItemRule } from 'element-plus'
import { buildValidatorData } from '/@/utils/validate'

const formRef = ref<FormInstance>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()


// baTable.table.extend.admin_id


const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    price: [buildValidatorData({ name: 'number', title: t('goods.goods.price') })],
    supply_discount: [buildValidatorData({ name: 'number', title: t('goods.goods.supply_discount') })],
    supply_price: [buildValidatorData({ name: 'number', title: t('goods.goods.supply_price') })],
    create_time: [buildValidatorData({ name: 'date', title: t('goods.goods.create_time') })],
})
</script>

<style scoped lang="scss"></style>
